﻿#include "./forms/VisualizeDataServer.h"
#include <QtWidgets/QApplication>
#include "customControl/DialogFrame.h"
#include "Socket_Thread.h"
#include <QSettings>
#include<QFileInfo>
#include "qfile.h"

//创建默认函数
void CreatDefaultConfigFile(QSettings *settings)
{
	QString grounpName = "Socket";
	
	settings->setValue("/" + grounpName + "/ipAddress" ,"127.0.0.1");
	settings->setValue("/" + grounpName + "/portNumber", 3442);
	settings->sync();

}

//判断文件是否存在
bool isFileExist(QString fullFileName)
{
	QFileInfo fileInfo(fullFileName);
	if (fileInfo.isFile())
	{
		return true;
	}
	return false;
}

//初始化
void initParams()
{
	//默认路径
	QString filePath = QCoreApplication::applicationDirPath();
	QString defaultPath = filePath + "/config.ini";
	//init 参数
	QSettings *setting = new QSettings(defaultPath, QSettings::IniFormat);
	//若配置文件不存在，创建默认配置文件
	if (!isFileExist(defaultPath))
	{
		CreatDefaultConfigFile(setting);
	}
	DataCenter::GetInstance().serverInfo.ipAddress = setting->value("Socket/ipAddress").toString();
	DataCenter::GetInstance().serverInfo.portNumber = setting->value("Socket/portNumber").toInt();
	setting->deleteLater();
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
	//初始化
	initParams();

    QString qssFile = ":/qss/Dark.qss";
    QFile file(qssFile);
    if (file.open(QFile::ReadOnly)) {
        QString qss = QLatin1String(file.readAll());
        QString paletteColor = qss.mid(20, 7);
        qApp->setPalette(QPalette(QColor(paletteColor)));
        qApp->setStyleSheet(qss);
        file.close();
    }
    //设置应用程序强制光标为 cursor 
    QPixmap pixmap = QPixmap(":/images/pointer.png");
    QSize size(32, 32);
    pixmap = pixmap.scaled(size, Qt::KeepAspectRatio);
    QCursor appCursor(pixmap, 10, 5);
    //用成员函数设置图标
    QApplication::setOverrideCursor(appCursor);
    //删除后 恢复到原来的 鼠标初始样式
    //删除载入的图
    //QApplication::restoreOverrideCursor();

    VisualizeDataServer w;
    w.showMaximized();
  /*  DialogFrame dlg;
    dlg.exec();*/

	Socket_Thread socket_Thread;
	socket_Thread.start();

    return a.exec();
}
